﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace MicoBenchmarks
{
	[StructLayout(LayoutKind.Sequential)]
	struct Vector3
	{
		public float X, Y, Z;

		public Vector3(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		public static Vector3 operator+(Vector3 p1, Vector3 p2) {return new Vector3(p1.X+p2.X, p1.Y+p2.Y, p1.Z+p2.Z);}

		public override string ToString()
		{
			return string.Format("{0}, {1}, {2}", X, Y, Z);
		}
	}

	static class Casting
	{
		public static void RunStructTest(Stopwatch stopwatch, float randomValue)
		{
			long mil = 0;
			//object vector = null, vector2 = null;
			Vector3 vector = new Vector3(), vector2 = new Vector3();
			for (int test = 0; test != 100; ++test)
			{
				stopwatch.Reset();
				stopwatch.Start();
				vector = new Vector3(randomValue * .25f, randomValue * 1.4f, randomValue * 1.11f);
				vector2 = new Vector3(randomValue * .33f, randomValue * .5f, randomValue * .4f);
				for (uint i = 0; i != 3000000; ++i)
				{
					//vector = (Vector3)vector + (Vector3)vector2;
					vector = vector + vector2;
				}
				stopwatch.Stop();
				mil += stopwatch.ElapsedMilliseconds;
			}

			mil /= 100;
			Console.WriteLine(string.Format("RunStructTest: Value={0}, Value2={1}, Mil={2}", vector, vector2, mil));
		}
	}
}
